package gui;

import static gui.BvViewI.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.LayoutManager;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
// TODO : make a border with title

public class ImagePanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JLabel label;
	JScrollPane scrollPane;
	
	public JScrollPane getScrollPane() {
		return scrollPane;
	}
	public ImagePanel(String title) {
		super();

		// Create Label (Actually an image)
		this.label = new JLabel(title, SwingConstants.CENTER);
		label.setBackground(Color.BLACK);
		label.setOpaque(true);
		
		label.setVerticalTextPosition(SwingConstants.TOP);
		label.setHorizontalTextPosition(SwingConstants.CENTER);
		Border blackline = BorderFactory.createLineBorder(Color.black);
		label.setBorder(blackline);
		
		// Create a scroll pane.
		this.scrollPane = new JScrollPane();
		scrollPane.setPreferredSize(new Dimension(IMAGE_PANE_WIDTH,IMAGE_PANE_HEIGHT));

		scrollPane.getViewport().add(label);
		this.add(scrollPane);
	}
	
	public void initPanel() {
		label.setIcon(null);
		label.revalidate();
		label.repaint();
		scrollPane.repaint();
	}
	public void updateImage(IplImage newImage) {
		ImageIcon icon = new ImageIcon(newImage.getBufferedImage());
		label.setIcon(icon);
		label.revalidate();
		label.repaint();
		scrollPane.repaint();
	}

	public ImagePanel(LayoutManager layout) {
		super(layout);
		// TODO Auto-generated constructor stub
	}

	public ImagePanel(boolean isDoubleBuffered) {
		super(isDoubleBuffered);
		// TODO Auto-generated constructor stub
	}

	public ImagePanel(LayoutManager layout, boolean isDoubleBuffered) {
		super(layout, isDoubleBuffered);
		// TODO Auto-generated constructor stub
	}

}
